/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PromoteAssign.java
 *
 * Created on Aug 3, 2013, 2:35:02 PM
 */
package Forms;

import Classes.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mau
 */
public class PromoteAssign extends javax.swing.JFrame {
    static MInterface mi;
    static User user;
    String port;
    _Login l = new _Login();
    
    ArrayList<Student> listStud;
    ArrayList<Student> promote;
    
    ArrayList<Sections> listSec;
    
    DefaultTableModel tbl1 = new DefaultTableModel();
    DefaultTableModel tbl2 = new DefaultTableModel();
    
    Student s;
    
    /** Creates new form PromoteAssign */
    public PromoteAssign(MInterface i, User cUser) {
        initComponents();
        mi = i;
        user = cUser;
        unameLbl.setText(user.getName());
        cUser = user;
        port = l.serverAdd;        
        
        try {
            syCB.removeAllItems();
            ArrayList<String> listsy = (ArrayList<String>) mi.getList("getlist-sylist").clone();
            for(int x = 0; x < listsy.size(); x++) {
                syCB.addItem(listsy.get(x));            
            }
            
            if(syCB.getSelectedIndex() != syCB.getItemCount() - 1) {
                syLbl.setText(syCB.getItemAt(syCB.getSelectedIndex() + 1) + "");
            }
            
            currCB.removeAllItems();
            clevelCB.removeAllItems();
            ArrayList<ClassLevel> listcurrlvl = (ArrayList<ClassLevel>) mi.getList4("getlist4-level-sy", syCB.getSelectedItem().toString()).clone();
            for(int x = 0; x < listcurrlvl.size(); x++) {
                currCB.addItem(listcurrlvl.get(x).getClassCategory());   
                clevelCB.addItem(listcurrlvl.get(x).getClassName());
                newlvlCB.addItem(listcurrlvl.get(x).getClassName());
            }
            
            secCB.removeAllItems();
            listSec = (ArrayList<Sections>) mi.getList4("getlist4-seclvl", newlvlCB.getSelectedItem().toString()).clone();
            for (int x = 0; x < listSec.size(); x++) {
                secCB.addItem(listSec.get(x).getSect());                
            }  
            listSec = (ArrayList<Sections>) mi.getList4("getlist4-secslots", secCB.getSelectedItem().toString()).clone();
            for (int x = 0; x < listSec.size(); x++) {
                no2Lbl.setText(listSec.get(x).getSlots()+"");
            }
            
            loadStudent();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void loadStudent() {
        try {
            listStud = (ArrayList<Student>) mi.getList3("getlist3-studsylevel", syCB.getSelectedItem().toString(), clevelCB.getSelectedItem().toString()).clone();
            no1Lbl.setText(listStud.size() + "");            
            tbl1 = new DefaultTableModel(new String[] {studTable1.getColumnName(0), studTable1.getColumnName(1), studTable1.getColumnName(2), studTable1.getColumnName(3)}, 0);
            studTable1.setModel(tbl1);
            for (int x = 0; x < listStud.size(); x++) {
                Student st = listStud.get(x);
                tbl1.insertRow(x, new Object[] {st.getSID(), st.getName(), st.getSchoolYear(), st.getGeneralAverage()});
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
//    public void getSlotsAvail() {
//        try {
//            ArrayList<Sections> secSlots = (ArrayList<Sections>) mi.getList4("getlist4-secslots", secCB.getSelectedItem().toString()).clone();
//            for (int x = 0; x < secSlots.size(); x++) {
//                no2Lbl.setText(secSlots.get(x).getSlots() + "");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bannerL = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        unameLbl = new javax.swing.JLabel();
        searchFld = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        currCB = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        syCB = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        clevelCB = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        newlvlCB = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        secCB = new javax.swing.JComboBox();
        syLbl = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        studTable1 = new javax.swing.JTable(){     
            public boolean isCellEditable(int rowIndex, int colIndex){         
                return false;     
            } 
        };
        jPanel2 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        studTable2 = new javax.swing.JTable(){     
            public boolean isCellEditable(int rowIndex, int colIndex){         
                return false;     
            } 
        };
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        no1Lbl = new javax.swing.JLabel();
        no2Lbl = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Promote and Assign Student");

        bannerL.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/banner.jpg"))); // NOI18N
        bannerL.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setText("Logout");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        unameLbl.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        unameLbl.setText("username");

        searchFld.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jButton2.setText("Search");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Curriculum:");

        currCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("School Year:");

        syCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        syCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                syCBActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Class Level:");

        clevelCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        clevelCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clevelCBActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("Promoted to:");

        newlvlCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        newlvlCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newlvlCBActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("Section:");

        secCB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        secCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                secCBActionPerformed(evt);
            }
        });

        syLbl.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        syLbl.setText("School Year");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(currCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(syCB, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clevelCB, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(112, 112, 112)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newlvlCB, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(secCB, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
                .addComponent(syLbl)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(currCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(syCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(clevelCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(newlvlCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(syLbl)
                    .addComponent(jLabel6)
                    .addComponent(secCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        studTable1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        studTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Number", "Student Name", "School Year", "General Average"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(studTable1);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButton3.setText("Add >>");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("<html>Remove<br> &nbsp;&nbsp;&nbsp;&lt;&lt;</html>");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(151, Short.MAX_VALUE)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(148, 148, 148))
        );

        studTable2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        studTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Number", "Student Name", "School Year", "Class Level", "Section"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(studTable2);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("No. of Entries:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setText("Slots Available:");

        no1Lbl.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        no1Lbl.setText("00");

        no2Lbl.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        no2Lbl.setText("00");

        jButton5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton5.setText("Save");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton6.setText("Cancel");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(no1Lbl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 595, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(no2Lbl)
                .addGap(354, 354, 354)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton6)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(no1Lbl)
                    .addComponent(no2Lbl))
                .addContainerGap(40, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1335, Short.MAX_VALUE)
                    .addComponent(bannerL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 1335, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(searchFld, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 848, Short.MAX_VALUE)
                        .addComponent(unameLbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 608, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bannerL, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(unameLbl))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(searchFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        this.hide();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int x = JOptionPane.showConfirmDialog(null,"Are you sure you want to logout already?","Alert!",JOptionPane.YES_NO_OPTION);        
        if(x == JOptionPane.YES_OPTION){
            try {
                mi.logout(user.getUsername());
                mi.clientActivity(user.getUsername(), "logout");
                this.setVisible(false);
                new _Login().setVisible(true);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void syCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_syCBActionPerformed
        loadStudent();
        if(syCB.getSelectedIndex() != syCB.getItemCount() - 1) {
            syLbl.setText(syCB.getItemAt(syCB.getSelectedIndex() + 1) + "");
        } 
    }//GEN-LAST:event_syCBActionPerformed

    private void newlvlCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newlvlCBActionPerformed
        try {
            secCB.removeAllItems();
            ArrayList<Sections> listSec = (ArrayList<Sections>) mi.getList4("getlist4-seclvl", newlvlCB.getSelectedItem().toString()).clone();
            for (int x = 0; x < listSec.size(); x++) {
                secCB.addItem(listSec.get(x).getSect());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_newlvlCBActionPerformed

    private void clevelCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clevelCBActionPerformed
        loadStudent();
    }//GEN-LAST:event_clevelCBActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (studTable1.getSelectedRowCount() == 0) {
            JOptionPane.showMessageDialog(null, "Please select a student/s to promote", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (studTable1.getSelectedRowCount() >= 1) {            
            studTable2.setModel(tbl1);
            tbl1.insertRow(studTable2.getRowCount(), new Object[] {s.getSID(), s.getName(), syLbl.getText(), newlvlCB.getSelectedItem(), secCB.getSelectedItem()});                            
            no2Lbl.setText(listStud.size() + "");
        }   
    }//GEN-LAST:event_jButton3ActionPerformed

    private void secCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secCBActionPerformed
        try {
            listSec = (ArrayList<Sections>) mi.getList4("getlist4-secslots", secCB.getSelectedItem().toString()).clone();
            for (int x = 0; x < listSec.size(); x++) {
                no2Lbl.setText(listSec.get(x).getSlots()+"");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_secCBActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try {
            boolean promote = false;
            if (studTable2.getRowCount() == 0) {
                JOptionPane.showMessageDialog(null, "Table is empty. There are no students to be proomoted", "Error", JOptionPane.ERROR_MESSAGE);
            } else {
                boolean exist = false;
                ArrayList<Student> stud = (ArrayList<Student>) mi.getList("getlist-students").clone();
                for(int x = 0; x < stud.size(); x++) {
                    if(stud.get(x).getSID().equals(studTable2.getColumnName(0))) {
                        exist = true;
                        promote = mi.add("add-promote", stud, null, user);
                        JOptionPane.showMessageDialog(null, "Student/s successfully promoted to " + newlvlCB.getSelectedItem().toString(), "Message", JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton5ActionPerformed
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PromoteAssign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PromoteAssign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PromoteAssign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PromoteAssign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PromoteAssign(mi, user).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bannerL;
    private javax.swing.JComboBox clevelCB;
    private javax.swing.JComboBox currCB;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JComboBox newlvlCB;
    private javax.swing.JLabel no1Lbl;
    private javax.swing.JLabel no2Lbl;
    private javax.swing.JTextField searchFld;
    private javax.swing.JComboBox secCB;
    private javax.swing.JTable studTable1;
    private javax.swing.JTable studTable2;
    private javax.swing.JComboBox syCB;
    private javax.swing.JLabel syLbl;
    private javax.swing.JLabel unameLbl;
    // End of variables declaration//GEN-END:variables
}
